package com.zwd.deep.controller;

import com.zwd.deep.common.RequestResult;
import com.zwd.deep.entity.dto.MedicationDto;
import com.zwd.deep.entity.vo.MedicationVo;
import com.zwd.deep.service.IMedicationsService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用药方案表
 *
 * @author zwd
 * @since 2025-02-12
 */
@RestController
@RequestMapping("/medications")
@AllArgsConstructor
@Slf4j
@Validated
public class MedicationsController {
    private final IMedicationsService medicationService;

    /**
     * 获取用药方案
     * @param diagnosisId 诊断记录ID
     * @return 用药方案列表
     */
    @GetMapping("/medication/diagnosis/{diagnosisId}")
    public RequestResult<List<MedicationVo>> getMedications(@PathVariable Integer diagnosisId) {
        log.info("getMedications diagnosisId: {}", diagnosisId);
        List<MedicationVo> medicationVos = medicationService.getMedications(diagnosisId);
        return RequestResult.success(medicationVos);
    }

    /**
     * 新增用药方案
     * @param medicationDto 用药方案参数
     * @return 新增结果
     */
    @PostMapping("/medication")
    public RequestResult<String> addMedication(@Validated @RequestBody List<MedicationDto> medicationDto) {
        log.info("addMedication medicationDto: {}", medicationDto);
        String result = medicationService.addMedication(medicationDto);
        return RequestResult.success(result);
    }

}
